package com.yuwj.chinaa.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.yuwj.chinaa.R;
import com.yuwj.chinaa.base.BaseActivity;
import com.yuwj.chinaa.presenter.IPresenter;
import com.yuwj.chinaa.presenter.presenterImpl.PresenterImpl;
import com.yuwj.chinaa.util.ToastUtil;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UserFeedbackActivity extends BaseActivity {

    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;
    IPresenter presenter;

    @Override
    public int setCustomContentViewResourceId() {
        return R.layout.activity_feedback;
    }

    public static Intent createIntent(Context context) {
        Intent intent = new Intent(context, UserFeedbackActivity.class);
        return intent;
    }

    @Override
    public void initParam() {
        presenter = new PresenterImpl(this);
    }

    @Override
    public void initView() {

    }

    @Override
    public void initOperator() {

    }

    @Override
    public void onUserFeedbackSuccess() {
        super.onUserFeedbackSuccess();
        ToastUtil.getInstance().shortLength(context, "反馈成功");
        finish();
    }

    @Override
    public void onUserFeedbackFail(Exception e) {
        super.onUserFeedbackFail(e);
        ToastUtil.getInstance().shortLength(context, e.getMessage());
    }

    @OnClick({R.id.iv_back, R.id.tv_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                onBackPressed();
                break;
            case R.id.tv_submit:
                String str = etContent.getText().toString();
                if (TextUtils.isEmpty(str)) {
                    ToastUtil.getInstance().shortLength(context, "请输入反馈内容");
                    return;
                }
                JSONObject param = new JSONObject();
                try {
                    param.put("feedbackCount", str);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                presenter.userFeedback(param.toString());
                break;
        }
    }
}
